We begin with deterministic compartmental models, which are usually straightforward to specify. With the right software, they are straightforward to solve. These models find application in virtually every scientific field. In public health, we see them most often in infectious disease epidemiology, cancer biology, pharmaco-kinetics, and healthcare operations research. We will use examples from Brauer, Castillo-Chavez, and Castillo-Chavez (2001 and others).
also here: https://institutefordiseasemodeling.github.io/Documentation/general/model-seir.html
The focus here is on specifying systems of ordinary differential equations, not on solving those systems analytically.
Consider the most boring model for a quantity \(y(x)\) \[ \frac{dy}{dx} = \beta \] with initial condition \(y(0)=\alpha\). The rate of change of \(y\) as a function of \(x\) is constant.
What function of \(t\) has slope \(\beta\) for every \(x\)? The linear function \[ y(x) = \alpha + \beta x . \] Have you seen this before?
Recall the linear “regression” model \[ y = \alpha + \beta x + \epsilon \] where \(\epsilon\) is a mean-zero error term.
If \(x\) is a treatment, and we regard \(y(x)\) as the potential outcome when treatment is set to \(x\), then the “treatment effect” is the change in \(y\) induced by a unit change in \(x\), \[ \frac{dy}{dx} = \beta \] This is one reason that some people (economists) think of causal effects as derivatives of outcome functionals.
Recall the basic birth process, where the rate of growth in \(y(t)\) is proportional to \(y(t)\) itself, \[ \frac{dy}{dt} = \lambda y(t) \] with initial condition \(y(0)=y_0\), which has solution \[ y(t) = y_0 e^{\lambda t} . \] When \(\lambda>0\), \(y(t)\) increases “exponentially”.
The “death” process is the same, but we let \(\lambda=-\mu<0\). Then \[ \frac{dy}{dt} = -\mu y(t) \] with initial condition \(y(0)=y_0\), which has solution \[ y(t) = y_0 e^{-\mu t} \] and \(y(t)\) decreases/decays “exponentially” toward zero.
Recall the exponential growth model \[ \frac{dy}{dt} = \lambda y(t) \] with initial condition \(y(0)=y_0\). Its solution is \(y(t) = y_0 e^{\lambda t}\). As \(t\to\infty\), \(y(t)\to\infty\). This unbounded growth may be unrealistic. For example, resource constraints may prevent cells from dividing indefinitely.
Suppose \(K\) is the “carrying capacity” of the medium, and \(\lambda\) is the intrinsic gowth rate as above. Consider the model \[ \frac{dy}{dt} = \lambda y(t)\left( 1 - \frac{y(t)}{K}\right) \] with initial condition \(y(0) = y_0\). This is just like the pure birth model, except there is a negative quadratic term.
\[ \frac{dy}{dt} = \lambda y(t)\left( 1 - \frac{y(t)}{K}\right) \]
\(y(t)\) is constant when \(dy/dt=0\), which occurs whe either \(y(t)=0\) or \(y(t)=K\). Therefore
In fact, the solution can be written down precisely: \[ y(t) = \frac{K y_0}{y_0 + (K-y_0)e^{-\lambda t}} \]
Consider a population of individuals where every individual is susceptible or infected with an infectious disease. Let \(S(t)\) be the proportion of susceptibles, and let \(I(t)\) be the proportion of infectives. Then the system is characterized by \[ \frac{dI}{dt} = \beta S(t) I(t) \] where \(S(t) + I(t) = 1\). We can rewrite this model as a logistic growth model with \(K=1\) and \(\lambda=\beta\) and \(y_0=I(0)\) above.
Consider a population of \(N\) individuals where every individual is susceptible or infected or recovered. Let \(S(t)\) be the number of susceptibles, \(I(t)\) be the number of infectives, \(R(t)\) the number of recovered. Then the system is characterized by
\[ \begin{aligned} \frac{dS}{dt} &= -\beta S(t) I(t) \\ \frac{dI}{dt} &= \beta S(t) I(t) - \gamma I(t) \\ \frac{dR}{dt} &= \gamma I(t) \end{aligned} \]
with initial condition \(S_0\), \(I(0)\), \(R(0)\) and conservation equation \(S(t)+I(t)+R(t)=N\).
Now suppose there is a latent period following infection that delays onset of infectiousness. Individuals in this latent state are exposed, but not yet infectious.
\[ \begin{aligned} \frac{dS}{dt} &= -\beta S(t) I(t) \\ \frac{dE}{dt} &= \beta S(t) I(t) - \delta E(t) \\ \frac{dI}{dt} &= \delta E(t) - \gamma I(t) \\ \frac{dR}{dt} &= \gamma I(t) \end{aligned} \]
For what infectious diseases might a latent period be important? How does this change our interpretation of \(I(t)\)?
Let’s incorporate births and deaths and model the absolute number of individuals in each compartment instead of the proportion. Let \(N(t) = S(t) + E(t) + I(t) + R(t)\). Let \(\nu\) be the per-person birth rate, and let \(\nu\) be the per-person death rate.
\[ \begin{aligned} \frac{dS}{dt} &= \mu N(t) - \nu S(t) -\beta S(t) I(t) \\ \frac{dE}{dt} &= \beta S(t) I(t) - (\nu + \delta) E(t) \\ \frac{dI}{dt} &= \delta E(t) - (\nu + \gamma) I(t) \\ \frac{dR}{dt} &= \gamma I(t) - \nu R(t) \end{aligned} \]
Now an “outbreak” can re-start after slowing down due to re-introduction of new susceptibles.
\[ \begin{aligned} \frac{dS}{dt} &= -\beta S(t) I(t) + \sigma R(t) \\ \frac{dE}{dt} &= \beta S(t) I(t) - \delta E(t) \\ \frac{dI}{dt} &= \delta E(t) - \gamma I(t) \\ \frac{dR}{dt} &= \gamma I(t) - \sigma R(t) \end{aligned} \]
When is loss of immunity due to prior infection important? For which diseases?
\[ \begin{aligned} \frac{dD}{dt} &= \lambda_D I(t) - (\lambda_L + \mu) D(t) \\ \frac{dL}{dt} &= \lambda_L D(t) - (\lambda_A + \mu) L(t) \\ \frac{dA}{dt} &= \lambda_A L(t) - (\lambda_S + \mu) A(t) \\ \frac{dS}{dt} &= \lambda_S A(t) - \mu S(t) \\ \end{aligned} \]
Adapted from Gonsalves et al. (2017).
Gonsalves et al. (2017)
[add diagram]
Let \(S(t)\) be the proportion of the population who do not use opiates, \(D(t)\) the population that do use opiates, and \(T(t)\) the proportion in treatment.
\[ \begin{aligned} \frac{dS}{dt} &= -\alpha S(t) -\beta S(t) D(t) + \sigma R(t) \\ \frac{dD}{dt} &= \delta E(t) - \gamma D(t) \\ \frac{dT}{dt} &= \gamma D(t) - \sigma T(t) \end{aligned} \]
[cite olya’s and maragret’s and ed’s paper? ]
Let \(G(t)\) be the amount of drug in the GI tract, \(B(t)\) in the bloodstream, and \(O(t)\) in the organ of interest. Let \(I(t)\) be the known input dynamics of drug administration (oral, IV, etc).
\[ \begin{aligned} \frac{dG}{dt} &= I(t) - \lambda_G G(t) \\ \frac{dB}{dt} &= \lambda_G G(t) - \mu_B(t) - \lambda_T B(t) \\ \frac{dO}{dt} &= \lambda_T B(t) - \mu_O O(t) \end{aligned} \]
The \(\lambda\) parameters represent rates of transition to the next compartment, and \(\mu\) parameters represent rates of clearance.
lsodaLots of ODEs can’t be solved analytically. For (well-behaved) systems that have a unique solution, it is often possible to solve for \(y(t)\) numerically, without having any calculus-style analytic insight into the structure of the solution. There are very fast computer algorithms for doing this.
We will focus on methods implemented in standard software packages.
library(deSolve)you will need to install this.
For help, look at ?deSolve
library(deSolve)
sir.model <- function(t, x, params) {
S <- x[1]
I <- x[2]
R <- x[3]
with(as.list(params), {
dS <- -beta * S * I
dI <- beta * S * I - gamma * I
dR <- gamma * I
dx <- c(dS, dI, dR)
list(dx)
})
}times <- seq(0, 120, by = 1)
params <- c(beta = 0.4, gamma = 1/7)
xstart <- c(S = 9999/10000, I = 1/10000,
R = 0)
out <- as.data.frame(lsoda(xstart, times,
sir.model, params))plot(out$time, out$I, ylab = "Population proportion",
xlab = "Time", type = "l", bty = "n",
ylim = c(0, 1), col = "red", lwd = 2)
lines(out$time, out$S, col = "green", lwd = 2)
lines(out$time, out$R, col = "blue", lwd = 2)
legend(100, 0.5, c("S(t)", "I(t)", "R(t)"),
lty = 1, col = c("green", "red", "blue"))sir.model <- function(t, x, params) {
S <- x[1]
I <- x[2]
R <- x[3]
with(as.list(params), {
dS <- -beta * S * I
dI <- beta * S * I - gamma * I
dR <- gamma * I
dx <- c(dS, dI, dR)
list(dx)
})
}First, we see that we have created a function sir.model, which is a funciton of time t, a model state x, and parameters params. The state x is a three-component vector corresponding to the S, I, and R states of the model.
sir.model <- function(t, x, params) {
S <- x[1]
I <- x[2]
R <- x[3]
with(as.list(params), {
dS <- -beta * S * I
dI <- beta * S * I - gamma * I
dR <- gamma * I
dx <- c(dS, dI, dR)
list(dx)
})
}The with function takes a list of parameters and does an action (contained in the curly brace block) using those parameters in memory. The action here is definition of the derivatives dS, dI, and dR, and putting these together in a list.
times <- seq(0, 120, by = 1)
params <- c(beta = 0.4, gamma = 1/7)
xstart <- c(S = 9999/10000, I = 1/10000,
R = 0)This part just sets up some times where we will evaluate the model, some parameters, and starting conditions.
lsodaHere is the most important part
out <- as.data.frame(lsoda(xstart, times,
sir.model, params))The lsoda function takes these arguments and solves the system for every time in times. We store the result as a data frame instead of as a list. Here is what out looks like
head(out)## time S I R
## 1 0 0.9999000 0.0001000000 0.000000e+00
## 2 1 0.9998541 0.0001294936 1.638852e-05
## 3 2 0.9997947 0.0001676659 3.760126e-05
## 4 3 0.9997179 0.0002170761 6.506202e-05
## 5 4 0.9996191 0.0002805687 1.003539e-04
## 6 5 0.9994911 0.0003628204 1.460811e-04
ODEs are most interesting when there are interactions between compartments.
Brauer, Fred, Carlos Castillo-Chavez, and Carlos Castillo-Chavez. 2001. Mathematical Models in Population Biology and Epidemiology. Vol. 40. Springer.
Gonsalves, Gregg S, A David Paltiel, Paul D Cleary, Michael J Gill, Mari M Kitahata, Peter F Rebeiro, Michael J Silverberg, et al. 2017. “A Flow-Based Model of the Hiv Care Continuum in the United States.” Journal of Acquired Immune Deficiency Syndromes (1999) 75 (5). NIH Public Access: 548–53.